//从文本中拿取数据
//
#include<stdio.h>
#include<string.h>

int main()
{
	FILE *fp=NULL;
	FILE *fp1=NULL;
	FILE *fp2=NULL;
	FILE *fp3=NULL;
	char buff[255];
  	char *temp[20];
	char *ret,*str;
	int i;
			
//将文本中解析除各精度
	fp=fopen("GPS.txt","r");
	fp1=fopen("PDOP.txt","a+");
	fp2=fopen("HDOP.txt","a+");
	fp3=fopen("VDOP.txt","a+");

	while(!feof(fp))
	{
		i=0;
		memset(buff,0,255);
		fgets(buff,255,(FILE*)fp);
		
		if(strstr(buff,"$GNGSA")!=NULL)
		{
		   //分割字符串
		   ret=strtok(buff,",");
			while((ret=strtok(NULL,","))!=NULL)
			{
				temp[i]=ret;
				i++;
			}

			//i 很关键，用来定位各元素的位置
			i--;
		//	printf("VDOP垂直精准度因子：%s\n",strtok(temp[i],"*"));
			str=strtok(temp[i],"*");
			fprintf(fp3," %s",str);
			i--;
		//	printf("HDOP水平精准度因子：%s\n",temp[i]);
		
			fprintf(fp2," %s",temp[i]);
			i--;
		//	printf("PDOP综合精准度因子：%s\n",temp[i]);
			fprintf(fp1," %s",temp[i]);
		}  
	}
	fclose(fp);
	fclose(fp1);
	fclose(fp2);
	fclose(fp3);
}
